package com.umpay.config;

import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.umpay.exception.BusinessException;
import com.umpay.interceptor.LoggerInterceptor;
import com.umpay.interceptor.ValidatorInterceptor;

/**
 * 注册拦截器
 * 
 * @ClassName InterceptorConfiguration
 * @Description TODO
 * @author FENG JUN LIU
 * @Date 2018年1月9日
 * @version 1.0.0
 */
@Component
public class InterceptorConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器
        registry.addInterceptor(new LoggerInterceptor() {

            @Override
            protected String getSign(String data) {
                return null;
            }
        }).addPathPatterns("/**").excludePathPatterns("/**.html");
        registry.addInterceptor(new ValidatorInterceptor() {

            @Override
            protected void checkParam(Map<String, Object> map) throws BusinessException {
                // map类型校验规则，业务线自定义
            }

            @Override
            protected String getSign(String data) {
                return null;
            }
        }).addPathPatterns("/**").excludePathPatterns("/**.html");
    }
}
